// Copyright (c) 2022 Presto Labs Pte. Ltd.
// Author: qiangluo

#pragma once
#include <memory>
#include <string>
#include <unordered_map>

namespace coin2::exchange::base::symbology {

class FileMonitor {
 public:
  FileMonitor(int64_t check_interval);

  bool AddFile(const std::string& path);
  void RemoveFile(const std::string& path);
  bool IsFileUpdated(const std::string& path);
  bool UpdateLastChangeTime(const std::string& path);
  bool HasFile(const std::string& path);

 private:
  struct record {
    int64_t last_check_time;
    int64_t last_change_time;
    std::string path;
    bool is_updated;
  };

  std::unordered_map<std::string, std::unique_ptr<record>> monitor_file_map_;
  int64_t check_interval_;
};
}  // namespace coin2::exchange::base::symbology
